package com.qzsf.backend.mapper;

import com.qzsf.backend.dto.OrganizerDetailDTO;
import com.qzsf.backend.entity.OrganizerProfile;
import com.qzsf.backend.mapper.sql.OrganizerSqlProvider;
import com.qzsf.backend.vo.OrganizerBasicInfoVO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/*
 * @Author: Dennis Chen
 * @CreateTime: 2024/11/13 15:39 周三
 * @Email 1429278462@qq.com
 * @Remark 组织详细信息数据访问层
 * @Version 1.0
 */
@Mapper
@Repository
public interface OrganizerProfileMapper {
    @Select("select a.id,a.status,b.name,b.pic,b.contact_name,b.contact_email,b.contact_phone,b.description from userauth a left join organizer_profile b on a.id = b.id where role = 'ORGANIZER'")
    List<OrganizerDetailDTO> getAllOrganizerDetail();

    @Insert("insert into organizer_profile (id,name, pic, contact_name, contact_email, contact_phone, description) VALUES (#{id},#{name}, #{pic}, #{contactName}, #{contactEmail}, #{contactPhone}, #{description})")
    int createOrganizer(OrganizerProfile organizerProfile);

    @Update("update organizer_profile set name = #{name},pic = #{pic},contact_name = #{contactName},contact_email = #{contactEmail},contact_phone = #{contactPhone},description = #{description} where id = #{id}")
    int updateOrganizer(OrganizerProfile organizerProfile);


    @Select("select * from organizer_profile where id = #{id}")
    OrganizerProfile getOrganizerProfileById(int id);

    @SelectProvider(type = OrganizerSqlProvider.class, method = "getOrganizerByCondition")
    List<OrganizerDetailDTO> getOrganizerDetail(String name);

    @Select("select a.name,a.pic,COUNT(b.id) AS eventCount from organizer_profile a left join event b on a.id = b.auth_id where a.id = #{id} group by a.id")
    OrganizerBasicInfoVO getOrganizerBasicInfo(int id);

    @Select("select * from organizer_profile")
    List<OrganizerProfile> getAllOrganizerProfileMobile();
}
